Facebook: App安装/授权页面 PHP代码示例

Categories: Java; Tagged with: ; @ December 4th, 2010 13:26

App安装界面:

image

1. Facebook中配置App:

image

2. 首页代码(index.php):

<?php
// Awesome Facebook Application
//
// Name: PushFromJava
//

require_once 'client/facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => 'App Key',
  'secret' => 'App Secrect Key',
  'cookie' => true,
));

$session = $facebook->getSession();
$fbme = null;
$loginUrl = $facebook->getLoginUrl(array('canvas' => 1,
                                          'fbconnect' => 0,
                                          'req_perms' => 'publish_stream', // 要求权限
                                          'next' => $canvas_base_url . 'welcome.php', // 安装成功后转向地址
                                          'cancel_url' => $canvas_base_url ));
    echo '{script}top.location.href = "' . $loginUrl . '"{/script}'; // 为了方便发布代码, 将

3. 将index.php及welcome.php上传到2中配置的地址

4. 安装结束后显示welcome.php中的内容.

如果需要直接安装, 则不需要创建任何界面, 直接访问:http://www.facebook.com/login.php?api_key=<!替换为自己的API_KEY!>

获得授权可访问:

http://www.facebook.com/login.php?api_key=APIKEYXxxxxxxxxxxxxxxxxx&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&req_perms=read_stream,publish_stream,offline_access

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.